@file:JvmMultifileClass
@file:JvmName("IfUtils")

package hos.kotlin

/**
 * <p>Title: ifExt </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @date : 2024-07-26 14:54
 * @version : 1.0
 */
inline fun doIf(condition: Boolean, block: () -> Unit) {
    if (condition) {
        block()
    }
}

inline fun <T> doIfResult(condition: Boolean, elseBlock: () -> T, block: () -> T): T {
    if (condition) {
        return block()
    }
    return elseBlock()
}

inline fun doIfWhere(condition: () -> Boolean, block: () -> Unit) {
    if (condition()) {
        block()
    }
}

fun <T> Boolean.then(trueValue: T, falseValue: T) = if (this) trueValue else falseValue


fun <T> Boolean.then(trueBlock: () -> T, falseBlock: () -> T) =
    if (this) trueBlock() else falseBlock()